{include file="public/account_head"}
<div id="vmsupplyItem">
    <div class="pub_wid notice_cont">
        <div class="mes_left rg">
            <div class="message bgb widthauto radius">
                <div>
                    <div class="message bgb widthauto radius">
                        <h6>发布></h6>
                        <ul class="att_box widthauto">
                            <li><span>所属分类：</span>
                                <a :class="{'cur':item_category==1}" @click="changeItemCategory(1)" class="choose">招标公告</a>
                                <a :class="{'cur':item_category==2}" @click="changeItemCategory(2)" class="choose">实时货源</a> </li>
                            <li><span>标题：</span>
                                <input v-model="itemData.title" name="" type="text"  class="bai" placeholder="请输入标题"/>
                            </li>
                            <li><span>服务类别：</span>
                                <select v-model="itemData.service_name" class="five">
                                    <option value="">选择类别</option>
                                    <option v-for="item in serviceList" :value="item.name">{{item.name}}</option>
                                </select>
                            </li>
                            <li><span>货物类别：</span>
                                <select v-model="itemData.trade_name" class="five">
                                    <option value="">选择类别</option>
                                    <option v-for="item in tradeList" :value="item.name">{{item.name}}</option>
                                </select>
                            </li>
                            <li id="distpicker"><span>地区：</span>
                                <select v-model="itemData.province" class="five">
                                    <option>请选择省</option>
                                </select>
                                <select v-model="itemData.city" class="five">
                                    <option>请选择城市</option>
                                </select>

                            </li>
                            <!--                <li><span>报名截止日期：</span>-->
                            <!--                    <select class="five">-->
                            <!--                        <option>请选择</option>-->
                            <!--                    </select>-->
                            <!--                </li>-->
<!--                            <li v-if="!isShowChangeEndTime"><span>投标截止日期：</span>-->
<!--                                {{itemData.end_time}}-->
<!--                            </li>-->
<!--                            <li v-if="isShowChangeEndTime"><span>投标截止日期：</span>-->
<!--                                <input v-model="itemData.end_time" id="end_time" name="" type="text" class="five" placeholder="请选择截止日期"/>-->
<!--                            </li>-->
                            <li><span>投标截止日期：</span>
                                <input v-model="itemData.end_time" @change="changeEndTime()" id="end_time" name="" type="text" class="five" placeholder="请选择截止日期"/>
                            </li>
                            <li><span>预算金额：</span>
                                <input v-model="itemData.budget" name="" type="text" class="five" placeholder="请输入金额"/>
                                万元/年</li>
                            <li><span>项目概况：</span>
                                <textarea v-model="itemData.item_about" name="" cols="" rows="" placeholder="请输入内容"></textarea>
                            </li>
                            <li><span>资格要求：</span>
                                <textarea v-model="itemData.certification_content" name="" cols="" rows="" placeholder="请输入内容"></textarea>
                            </li>
                            <li><span>项目内容：</span>
                                <textarea v-model="itemData.item_content" name="" cols="" rows="" placeholder="请输入内容"></textarea>
                            </li>
                            <li><span>附件：</span><a @click="pushAccessory()" class="add">点击添加</a>
                            </li>
                            <li class="reup" v-for="(item,index) in accessoryList"><span>&nbsp;</span>
                                <input name="" v-model="item.name" type="text"  class="wuba" placeholder="请输入标题"/>
                                <div style="margin: 5px 10px;" class="fileInput left">
                                    <input type="file" :ref="'upFileWord'+index"  :name="'upFileWord'+index" :id="'upFileWord'+index" @change="upWord($event,index)" class="upfile"/>
                                    <label class="upFileBtn" type="button" :for="'upFileWord'+index" ></label>
                                </div>
                                <div @click="removeFile(item)" class="notice_label_button notice_label_yellow">
                                    删除文档
                                </div>

                                <div @click="removeAccessory(index,item)" style=";" class="notice_label_button notice_label_danger">
                                    删除此项
                                </div>
                            </li>
                        </ul>
                        <div class="submit"><a @click="addNoticeItem()">提交审核</a></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="lf two_left">
            <div class="about_nav">
                <ul class="widthauto">
                    <li><a href="#" class="down" >账户中心</a></li>
                    <p class="widthauto">
                        <a href="/index/consignor/index">我的信息</a>
                        <a href="/index/consignor/reset" >修改密码</a>
                    </p>
                    <li>
                        <a href="/index/consignor/facilitator" >运力服务商</a>
                    </li>
                    <li>
                        <a href="/index/consignor/noticeList"  class="cur">我的发布</a>
                    </li>
                </ul>
            </div>
            <div class="add_box"> <a href="#"><img src="/static/index/public/images/add_008.jpg" /></a> </div>
        </div>
    </div>
</div>
    {include file="public/footer"}
<style>
    .choose {
        float: left;
        width: 20%;
        text-align: center;
        line-height: 40px;
        border: #aaa solid 1px;
        color: #333333;
        border-radius: 5px;
        margin-right: 20px;
    }
    .cur {
        border: #3267cb solid 1px;
        color: #3267cb;
    }
    .att_box li label {
        border: #aaa solid 1px;
        border-radius: 5px;
        box-sizing: border-box;
        padding: 0 10px;
        line-height: 38px;
        float: left;
    }
    .notice_label_button{
        border: none;
        border-radius: 5px;
        height: 34px;
        background-size: 100px;
        width: 100px;
        float: left;
        margin: 5px 10px;
        text-align: center;
        line-height: 34px;
        cursor: pointer;
    }
    .notice_label_yellow{
        background: #f8ac59;
        color: #fff;
    }
    .notice_label_danger{
        background: #ed5565;
        color: #fff;
    }
</style>
<!--全国省份-->
<script src="/static/util/distpicker/distpicker.min.js"></script>
<!--时间组件-->
<script src="/static/util/laydate/laydate.js"></script>
<script type="text/javascript">
    var id = "{$id}";
    var vmsupplyItem = new Vue({
        el:"#vmsupplyItem",
        data:{
            serviceList:[],//服务类型列表
            tradeList:[],//商品类别
            item_category:1,//发布类别，1.招标公告，2.实时货源
            itemData:{
            },
            end_time:'',
            member_id:'',
            id:'',
            accessoryList:[
                {"name":'',"fileUrl":''}
            ],
            isShowChangeEndTime:true
        },
        methods:{
            changeEndTime:function(){
                console.log(this.end_time)
            },
            changeItemCategory:function(num){
                this.item_category = num
            },
            getTradeChildList:function(){
                var el = this
                AjaxPost({"trade_id":2},'/index/trade/getTradeChildByWhere').then((response=>{
                    el.serviceList = response.result
                }))
                AjaxPost({"trade_id":1},'/index/trade/getTradeChildByWhere').then((response=>{
                    el.tradeList = response.result
                }))
            },
            addNoticeItem:function () {
                var el = this
                if(el.member_id == ''){
                    $.customToastr('error','未查询到会员信息，请重新登录')
                    return
                }
                var postDate = {
                    ...el.itemData,
                    'item_category':el.item_category,
                    'accessory_info':el.accessoryList,
                }
                AjaxPost({"id":el.id,"postDate":postDate},'/index/consignor/updateNoticeItem').then((response)=>{
                    if (response.status == 1){
                        this.shadeStatus = false
                        this.popupsStatus = false
                        $.customToastr('success','修改成功，请等待审核')
                        setTimeout(()=>{
                            window.history.back()
                        },1000)
                    }
                    console.log(response)
                })
            },
            getNoticeItem:function () {
                var el = this;
                if(el.id == ''){
                    window.location.href='/index/consignor/noticeList'
                }
                var postDate = {
                    "id":el.id
                }
                console.log(el.id)
                AjaxPost(postDate,'/index/consignor/getNoticeItemById').then((response)=>{
                    if (response.status == 1){
                        if(response.result == null){
                            window.location.href='/index/consignor/noticeList'
                        }else{
                            var itemData = response.result
                            el.item_category = itemData.item_category
                            $('#distpicker').distpicker({
                                province:itemData.province,
                                city:itemData.city
                            });
                            // el.end_time = itemData.end_time
                            laydate.render({
                                elem: '#end_time', //指定元素
                                value:itemData.end_time,
                                done: function (value,date,endDate) {
                                    el.itemData.end_time =value
                                }
                            });
                            if(itemData.accessory_info){
                                el.accessoryList = itemData.accessory_info
                            }
                            el.itemData = itemData
                            //判断是否能修改时间
                            // el.isShowSetEndTime(el.itemData.end_time,el.itemData.status)
                        }

                        // $.customToastr('success','添加成功，请等待审核')
                    }
                    console.log(response)
                })
            },
            upWord:function(event,num){
                var el = this
                layer.prompt({title: '请输入传入文件名称', formType: 2}, function(pass, index){
                    layer.close(index);
                    var files = event.target.files
                    var formData = new FormData();
                    formData.append('files',files[0]);
                    AjaxPost(formData,'/index/image/uploadWord').then((response=>{
                        el.accessoryList[num].name = pass
                        el.accessoryList[num].fileUrl = response.result;
                        console.log(response);
                        console.log(el.accessoryList);
                    }))
                });

            },
            pushAccessory:function () {
                var el = this
                el.accessoryList.push({"name":'',"fileUrl":""})
            },
            removeAccessory:function (num,item) {
                var el = this
                if(item.fileUrl==''){
                    el.accessoryList.splice(num,1)
                }else{
                    var postDate = {
                        "file" :item.fileUrl
                    }
                    AjaxPost(postDate,'/index/image/removeFile').then((response=>{
                        if(response.status == 1){
                            $.customToastr('success','图片删除成功')
                            el.accessoryList.splice(num,1)
                        }
                        console.log(response);
                    }))
                }
            },
            removeFile:function(item){
                if(item.fileUrl==''){
                    return $.customToastr('error','未上传文件')
                }else {
                    var postDate = {
                        "file" :item.fileUrl
                    }
                    AjaxPost(postDate,'/index/image/removeFile').then((response=>{
                        if(response.status == 1){
                            $.customToastr('success','图片删除成功')
                            item.name=''
                            item.fileUrl=''
                        }
                        console.log(response);
                    }))
                }
            },
            accessory_info_stringify:function (arrayData) {
                var newDate = []
                if(arrayData.length>0){
                    $.each(arrayData,(j,k)=>{
                        if(k.fileUrl != ''){
                            newDate.push(k)
                        }
                    })
                    return JSON.stringify(newDate)
                }else {
                    return ''
                }
            },
            isShowSetEndTime:function (time,status) {
                var el = this
                var time = time
                var status = status
                var nowTime = new Date().getTime();
                var setTime = new Date(time).getTime();
                console.log(nowTime)
                console.log(setTime)
                console.log(nowTime<setTime);
                if(setTime<nowTime){
                    el.isShowChangeEndTime = false;
                }
                if(status==4) {
                    el.isShowChangeEndTime = false;
                }


            }

        },
        mounted(){
            this.$nextTick(function () {
                this.getTradeChildList();
                // this.isShowSetEndTime()
                if(localStorage.getItem("memberId") != null){
                    this.member_id = localStorage.getItem("memberId")
                }
                if(id != null ){
                    this.id = id
                }

                this.getNoticeItem();
            })
            $(document).ready(function(){
                // 改为鼠标移上的事件只需把click改为mousemove
                $(".fortab").click(function(){
                    var number=$(".fortab").index(this);
                    $(this).addClass("checked");
                    $(this).siblings().removeClass("checked");
                    $(".tablelist:eq("+number+")").show();
                    $(".tablelist:eq("+number+")").siblings().hide();
                });

            });
        }
    })
</script>
